<template>
  <section>
    <el-tabs v-model="activeName">
      <el-tab-pane label="仓库信息" name="first">
        <warehouse :warehouse="currWarehouse" v-if="activeName === 'first'" v-on:confirm="createSuccess"/>
      </el-tab-pane>
      <el-tab-pane label="库存管理" name="second">
        <stock-list  v-if="activeName === 'second'" :currWarehouse="currWarehouse"></stock-list>
      </el-tab-pane>
      <el-tab-pane label="入库单" name="third">
        <inbound-list :currWarehouse="currWarehouse" v-if="activeName === 'third'"/>
      </el-tab-pane>
      <el-tab-pane label="出库单" name="fourth">
        <outbound-list  :currWarehouse="currWarehouse" v-if="activeName === 'fourth'"/>
      </el-tab-pane>
      <el-tab-pane label="入库任务" name="five">
        <task-in v-if="activeName === 'five'"></task-in>
      </el-tab-pane>
      <el-tab-pane label="出库任务" name="six">
        <task-out v-if="activeName === 'six'"></task-out>
      </el-tab-pane>
    </el-tabs>
  </section>
</template>

<script>
  import stockList from './stockManagement/stockList'
  import taskOut from './task/out'
  import taskIn from './task/in'
  import inboundList from './inbound/index'
  import outboundList from './outbound/index'
  import warehouse from './warehouse'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  import Vue from 'vue'//后续添加属性，需要vue联动
  import errHandler from '@/assets/errHandler'
  export default {
    name: "index",
    components:{warehouse,inboundList,outboundList,taskIn,taskOut,stockList},
    data(){
      return{
        activeName:null,
        currWarehouse:null
      }
    },
    created(){
      this.getWarehouse()
    },
    computed:{
      ...mapGetters(['department']),
    },
    watch: {
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      getWarehouse() {
        this.fetch({name: "getWarehouse", data: {departmentId: this.department.id}})
          .then(res => {
            console.log(res)
            this.currWarehouse=res
            this.activeName='first'
          })
          .catch(err => {
            if(err.errCode === 'warehouse_not_exist'){
              this.currWarehouse={name:'',code:'',departmentId:this.department.id,virtual:false,location:''}
              this.activeName='first'
              return
            }
            console.log(err)
            errHandler.handle(this, err)
          })
      },
      createSuccess(e){
        console.log('新建成功后，这里的仓库是啥------',this.currWarehouse.location)
        Vue.set(this.currWarehouse,'id',e.id)
      }
    }
  }
</script>

<style scoped>

</style>
